package cn.tedu.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class RedisController {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @RequestMapping("/redis")
    public void redis(){
        //expire ttl exists del
        redisTemplate.hasKey("name");
        redisTemplate.expire("name",2, TimeUnit.DAYS);
        redisTemplate.getExpire("name",TimeUnit.HOURS);
        redisTemplate.delete("name");
        //String
        ValueOperations<String, String> opsForValue = redisTemplate.opsForValue();
        opsForValue.increment("num",-100);
        //List
        ListOperations<String, String> opsForList = redisTemplate.opsForList();

    }
}
